import plugin from '../../lib/plugins/plugin.js'
import fetch from "node-fetch"
import { getGroupImageUrl, segment } from "oicq";
import { parseFunString } from 'oicq/lib/common.js';
import axios from'../../node_modules/.pnpm/axios@0.27.2/node_modules/axios/lib/axios.js'
/** 功能列表
 * 表情制作：#阿尼亚+@或者qq号，#黑化+@或者qq，#举牌+不超过4个字符的文字 #牵+@或者qq号|无空格
 * 查询功能：#星座运势 （星座） #天气 （城市） |有空格
 * 附加功能：#黑白化图片
 * 
 * 
 * 
 * 
 * 
 * */
 let i =0
 let qq1
 let qq2
export class example extends plugin {
  constructor () {
    super({
      /** 功能名称 */
      name: 'DJ表情插件',
      /** 功能描述 */
      dsc: '表情制作',

      event: 'message',
      /** 优先级，数字越小等级越高 */
      priority: 5000,
      rule: [
        


 {
          /** 命令正则匹配 */
          reg: '^#阿尼亚(.*)$',
          /** 执行方法 */
          fnc: 'any'
        }, 
        {
          /** 命令正则匹配 */
          reg: '^#黑化(.*)$',
          /** 执行方法 */
          fnc: 'hh'
        },
        {
          /** 命令正则匹配 */
          reg: '^#星座运势 (.*)$',
          /** 执行方法 */
          fnc: 'xz'
        },
        {
          /** 命令正则匹配 */
          reg: '^#举牌(.*)$',
          /** 执行方法 */
          fnc: 'jp'
        },
        {
          /** 命令正则匹配 */
          reg: '^#天气 (.*)$',
          /** 执行方法 */
          fnc: 'tq'
        },
        {
          /** 命令正则匹配 */
          reg: '^#黑白化图片$',
          /** 执行方法 */
          fnc: 'yzjd'
        },
        {
          /** 命令正则匹配 */
          reg: '^.*$',
          /** 执行方法 */
          fnc: 'getimg'
        },
        {
          /** 命令正则匹配 */
          reg: '^#牵(.*)$',
          /** 执行方法 */
          fnc: 'kd'
        }
      ]
    })
  }


      async any (e){
        if(!/\d/.test(e.msg)) {let targetQQ = e.at;let url ='http://xiaobapi.top/api/xb/api/any.php?qq='+targetQQ;
       console.log(url)
       await this.reply(segment.image(url),true)
             }
             else{console.log('1')
             qq2 = e.msg.replace('#阿尼亚','')
             let url ='http://xiaobapi.top/api/xb/api/any.php?qq='+qq2;
           console.log(url)
           e.reply(segment.image(url),true)
               console.log(qq2)}
            }
       async hh (e){
        if(!/\d/.test(e.msg)){let targetQQ = e.at;let url ='http://xiaobapi.top/api/xb/api/bqb_10.php?qq='+targetQQ
             console.log(url)
             await this.reply(segment.image(url),true)
                   }else{console.log('1')
                   qq2 = e.msg.replace('#黑化','')
                   let url ='http://xiaobapi.top/api/xb/api/bqb_10.php?qq='+qq2;
                 console.log(url)
                 e.reply(segment.image(url),true)
                     console.log(qq2)}}
     
             async xz (e){
              let msg = e.msg.replace('#星座运势 ','');
              let url ='http://xiaobapi.top/api/xb/api/xingzuo.php?msg='+msg;
             console.log(url)
             let res = await fetch(url)
             res = await res.text()
             console.log(res)
             await this.reply(res,true)
           
                   }
                   async jp (e){
                    let msg = e.msg.replace('#举牌','');
                    if(msg.length>4){await this.reply('输入长度不可大于4个字符'),true}else{
                    let url ='http://xiaobapi.top/api/xb/api/fans_jupai.php?msg='+msg;
                    let URL =encodeURI(url)
                    console.log(URL)
                    await this.reply(segment.image(URL),true)}}
                    async tq (e){
                      let msg = e.msg.replace('#天气 ','');
                      let url ='http://xiaobapi.top/api/xb/api/city.php?type=&msg='+msg;
                      let URL =encodeURI(url)
                      console.log(URL)
                      await this.reply(segment.image(URL),true)}
                  
                  
                      async yzjd (e){
                       
                           i=1
                           console.log(i)
                       this.reply('请发送图片',true)}
                 
                      
                      
                               
                  async getimg (e){
                    if (e.img==-1) {
                      return false;}
                      else if(i!==1){ return false}
                      else if(i==1&e.img!==-1){console.log(i)
                        if (e.isGroup) {
                        let reply = (await e.group.getChatHistory(e.img.seq, 1))
                              .pop()?.message;
                     
                      if (reply) {
                        for (let val of reply) {
                            if (val.type == "image") {
                                e.img = [val.url];
                                break;
                            }
                        }}
                        
                        
                       let x = 'http://xiaobapi.top/api/xb/api/hbimage.php?url='+e.img
                        console.log(x)
                      
                        await this.reply(segment.image(x),true)}

                        i=0
                       
                      }}

async kd (e){
  if(!/\d/.test(e.msg)){ qq2 = e.at; qq1 = e.user_id
    let url ='http://xiaobapi.top/api/xb/api/qian.php?qq='+qq1+'&qq2='+qq2;
    console.log(url)
    e.reply(segment.image(url),true)
    console.log(qq1+' '+qq2) }
                      else
              
                       {console.log('1')
                       qq1 = e.user_id
                       qq2 = e.msg.replace('#牵','')
                       let url ='http://xiaobapi.top/api/xb/api/qian.php?qq='+qq1+'&qq2='+String(qq2);
                     console.log(url)
                     e.reply(segment.image(url),true)
                         console.log(qq1+' '+qq2) }
                      
                      
                        }     } 
                  
                  
                        
                  
                  
                  
                  
                  
                  
                  